package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.work.domain.Product;
import com.ruoyi.work.query.ProductQuery;
import com.ruoyi.work.query.TablePageInfo;
import com.ruoyi.work.query.web.AjaxResult;
import com.ruoyi.work.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 客户控制器
 */
@Controller
@RequestMapping("demo/work")
public class ProductController extends BaseController  {
    //模板前缀
    private static final String prefix = "demo/work/";

    @Autowired
    private IProductService productService;
    //页面-----------------------------------s-------------------------

    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }

    @GetMapping("/aPage")
    public String aPage(){
        return prefix + "add";
    }


    @GetMapping("/editPage")
    public String editPage(Long id, Model model){
        model.addAttribute("product", productService.get(id));
        return prefix + "edit";
    }




    //数据-----------------------------------------------------------
    //列表

    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<Product> query(ProductQuery qo){
        return productService.query(qo);
    }

    //新增
    @PostMapping("/add")
    @ResponseBody
    public com.ruoyi.common.core.domain.AjaxResult addSave(String name, Integer price, Integer salePrice , String brand, String code , MultipartFile picture) throws Exception{
        return toAjax(productService.insertArticle(name,price,salePrice,brand,code,picture));
    }


    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(Product product){

        productService.update(product);
        return AjaxResult.success();
    }
   /* public com.ruoyi.common.core.domain.AjaxResult editSave(String name, Integer price, Integer salePrice , String brand, String code , MultipartFile picture) throws Exception{
        return toAjax(productService.update2(name,price,salePrice,brand,code,picture));
    }*/


    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        productService.deleteBatch(ids);
        return AjaxResult.success();
    }

}
